<!DOCTYPE html>
<html lang="en">

<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="../lib/jquery/jquery.js"></script>

    <script>
        function ajax() {
            return new Promise(function (resolve, reject) {
                $.ajax({
                    type: "get",
                    dataType: 'json',
                    url: 'http://localhost:3000',
                    success: function (data) {
                        return resolve(data);             //成功执行这个函数把参数带出去
                    }, error: function (error) {
                        return reject(error);             //失败执行这个函数把错误带出去
                    }
                })
            });
        }

        Promise.prototype.done = function (onFulfilled, onRejected) {
            this.then(onFulfilled, onRejected)
                .catch(function (reason) {
                    // 抛出一个全局错误
                    setTimeout(() => { throw reason }, 0);
                });
        };
        var aa=ajax()
        aa.then((data)=>{
            console.log(data)
            return new Error('aa')
        }).done((data)=>{
            console.log(data)
        })

    </script>
</head>

<body>

</body>

</html>